package com.hzlj.position.locate.service.impl;

import com.fz.common.base.core.db.BatchCUDUtil;
import com.hzlj.position.locate.common.dto.abnProhibitAreasJzry.AbnProhibitAreasJzryQueryParamDTO;
import com.hzlj.position.locate.common.dto.abnProhibitAreasJzry.AbnProhibitAreasJzryQueryResultDTO;
import com.hzlj.position.locate.common.dto.abnProhibitAreasJzry.AbnProhibitAreasJzryUpdateDTO;
import com.hzlj.position.locate.dao.AbnProhibitAreasJzryDao;
import com.hzlj.position.locate.service.AbnProhibitAreasJzryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.hzlj.position.config.config.IdConfig.POSITION_ID_GEN;

/**
 * 禁止区域-人员(AbnProhibitAreasJzry)表服务接口
 *
 * @author lifh
 * @date 2023-03-28 10:20:35
 */
@Slf4j
@Service
public class AbnProhibitAreasJzryServiceImpl implements AbnProhibitAreasJzryService {
    @Resource
    private AbnProhibitAreasJzryDao abnProhibitAreasJzryDao;


    @Override
    public void updateAbnProhibitAreasJzry(String prohibitId, List<AbnProhibitAreasJzryUpdateDTO> jzry) {
        jzry.forEach(e->{e.setProhibitId(prohibitId);});
        List<AbnProhibitAreasJzryQueryResultDTO> dbExistsRecords = abnProhibitAreasJzryDao.listAbnProhibitAreasJzry(new AbnProhibitAreasJzryQueryParamDTO().setProhibitId(prohibitId));
        BatchCUDUtil.batchCUD(
                jzry,
                dbExistsRecords,
                AbnProhibitAreasJzryUpdateDTO::getId,
                AbnProhibitAreasJzryQueryResultDTO::getId,
                e->{
                    e.setId(POSITION_ID_GEN.nextIdStr());
                },
                abnProhibitAreasJzryDao
        );
    }

    @Override
    public List<AbnProhibitAreasJzryQueryResultDTO> listAbnProhibitAreasJzry(String prohibitId) {
        AbnProhibitAreasJzryQueryParamDTO param = new AbnProhibitAreasJzryQueryParamDTO();
        param.setProhibitId(prohibitId);
        return abnProhibitAreasJzryDao.listAbnProhibitAreasJzry(param);
    }

}
